<%@ page contentType="text/html;charset=UTF-8" %>
<ul class="sidebar-menu" id="left-cate-menu-ul" data-widget="tree">

</ul>
<script>
    //定义cateTools参数变量
    cateTools={
        totalPage:"",
        sysName:"${r'${sysName}'}",
        cateMenuId:"cateMenu",
        leftMenuId:"left-cate-menu-ul",
        enableCate:false,
        enableTopTabMenu:false
    };
    $(function () {
        var cateMenuNo = "";
        if(cateTools.enableCate){//是否启用按品种切换
            initCateMenuData();
            cateMenuNo = localStorage.getItem("cateMenuNo");//切换其他菜单时获取之前存储的值
        }else{
            cateMenuNo = cateTools.sysName;
        }
        //alert(cateMenuNo);
        loadLeftCateMenu(cateMenuNo);

        //add 20180919 是否启用【动态tab菜单】
        if(cateTools.enableTopTabMenu){
            console.log("cateTools",cateTools);
            //判断页面是否存在
            var mynavlength=$("header").find("#mynav-menutop-tabs").length;
            var mynavObj = "<nav class=\"navbar navbar-nav mynav\" style=\"background-color:#edf1f5;\">";
            mynavObj +="<div class=\"nav nav-tabs hidden\" id=\"mynav-menutop-tabs\">";
            mynavObj +="</div>";
            mynavObj +="</nav>";
            if(mynavlength==0){//不存在则补充元素
                $("header").find("nav").after(mynavObj);
            }
        }

    });

    /**
     * add 【动态tab菜单】显示拼装的tab菜单数据
     * @param oldClickedMap
     */
    function showClickMenuItemMap(oldClickedMap){
        //遍历数据
        var clickedHtmls = "";
        for(var url in oldClickedMap){
            var urlTitle = oldClickedMap[url];
            //alert(url+"=="+location.pathname);
            var checkedCss="";
            if(url==location.pathname){
                checkedCss="btn-app2-active";
            }
            clickedHtmls+="<div class='tabios'>";
            clickedHtmls+="<a data-pjax=\"true\" href=\""+url+"\" class=\"btn btn-app2 "+checkedCss+"\">";
            clickedHtmls+="<span data-pjax-title='true'>"+urlTitle+"</span>";
            clickedHtmls+="</a>";
            if(url!=location.pathname){//未选中的才能删除。
                clickedHtmls+="<span class=\"badge bg-aqua\"><i class=\"fa fa-close fcur\" url='"+url+"'></i></span>";
            }
            clickedHtmls+="</div>";
        }
        //alert(clickedHtmls);
        //显示数据到top的tabs内
        if(!strUtil.isNull(clickedHtmls)){
            $("#mynav-menutop-tabs").removeClass("hidden");
            $("#mynav-menutop-tabs").html(clickedHtmls);
        }

        //4、添加点击删除事件
        $("#mynav-menutop-tabs").find(".fa-close").click(function(){
            var thisKey =$(this).attr("url");
            //alert(thisKey);
            delete oldClickedMap[thisKey];
            showClickMenuItemMap(oldClickedMap);
        });
    }
    /**
     * add 【动态tab菜单】
     * 控制pjax后，已经得到了从点击一个链接开始
     */
    $(document).on("pjax:clicked", function(options) {
        if(cateTools.enableTopTabMenu){
            //alert("发送完成");
            var oldClickedMap = {};
            //console.log(options);
            var currentObj = $(options.target);
            var key=currentObj.attr("href");
            var text=currentObj.text();
            //alert(options+"-->"+key+"-->"+text);

            //1、加载历史数据
            $("#mynav-menutop-tabs").find("a").each(function(){
                var old_key=$(this).attr("href");
                var old_val=$(this).find("[data-pjax-title='true']").text();
                //alert(old_key+"--->"+old_val);
                oldClickedMap[old_key]=old_val;
            });
            //2、插入新数据
            oldClickedMap[key]=text;
            //3、显示数据
            showClickMenuItemMap(oldClickedMap);
        }
    });

</script>
